package com.glls.java2212.controller;


import com.glls.java2212.common.LayuiPageVo;
import com.glls.java2212.common.R;
import com.glls.java2212.pojo.Student;
import com.glls.java2212.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @RequestMapping("/studentList")
    public LayuiPageVo<Student> studentPageData(@RequestParam Map<String,Object> params){
        // 注意 这里使用 map来接受参数  前端传的不定参数 都可以封装到 map 中
        System.out.println(params);
        return studentService.studentPageData(params);
    }

    @RequestMapping("/deleteStudent")
    public R deleteStudent(Integer id){
        int result = studentService.deleteStudentById(id);
        if (result == 1){
            return R.ok();
        }else {
            return R.error();
        }
    }
    @RequestMapping("/addStudent")
    public R addStudent(Student data){
        int result = studentService.addStudent(data);
        if (result == 1){
            return R.ok();
        }else {
            return R.error();
        }
    }

}
